I was recently trying out all the available algorithms to see which one worked the best at predicting the direction of a stock("GOOG"). I came accross Nearest Centroid Classification and decided to give it a shot. At first I ran it and got an expected 49 - 46% Accuracy. Then I found the "shrink_threshold" parameter and changed it to 0.5. Then for some crazy reason I started getting over 90% accuracy. Specifically over 98% most of the times while getting 0.995 And that was at the Train Data, split 80-20%( I have the code bellow so you can try it out ). Then I understood that something was wrong. I guess that the algorithm found out how the label was set (if Open>high then -1 else 1). Now I would like to use the algorithm to predict future direction of stock. To see if it has as good of accuracy as it does now (I don't think so but even a 60% would be impressive). What should I change at the data or the code?
Source Code:
import pandas as pd from sklearn.neighbors.nearest_centroid import NearestCentroid import numpy as np from sklearn import cross_validation
Data as .csv https://drive.google.com/file/d/0B_r3mf9HbUrLcmtQY1VTblNOd1k/view?usp=sharing
Any info, resources and help on how can I predict future stock price direction with classification is much appreciated.
You must be logged in to post. Please login or register an account.
Unfortunately, the reality of the situation is you cannot predict stock prices, certainly not with anything from scikit-learn. Even when you get something like 90% with a stock like GOOGL, that's because GOOGL is just a solid up-ward trend. You'd do better just buying and holding GOOGL, rather than trying to trade it.
Many brilliant people have dedicated their lives to predicting stock prices using machine learning. Lots of Google Scholar papers on the topic. If you're going to predict stock prices, you're going to do it by analyzing the company itself, not just by looking at patterns of prices. You can use ML algorithms to analyze fundamentals to find over-sold or over-bought companies, but that's just about it.
-Harrison 8 years ago
You must be logged in to post. Please login or register an account.
That's ok. Thankfully there are a lot of things Machine Learning can do other than Stock Prediction. I might look into some papers though from Google Scholars though. Thanks again for the info.
-Panagiotis Petridis 8 years ago
You must be logged in to post. Please login or register an account.